﻿using System.Web;
using System.Web.SessionState;

namespace Infrastructure.Storage
{
    public class SessionStorageAdapter : ISessionStorage
    {
        private readonly HttpSessionState _session = HttpContext.Current.Session;

        public void Add(string key, object data)
        {
            _session.Add(key, data);
        }

        public void Remove(string key)
        {
            _session.Remove(key);
        }

        public T Get<T>(string key) where T : class
        {
            try
            {
                return (T)_session[key];
            }
            catch
            {
                return null;
            }
        }
    }
}